package com.example.controller;
import com.example.pojo.Hotel;
import com.example.pojo.Result;
import com.example.service.HotelService;
import com.example.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.slf4j.Logger;//注意不要打错包
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@Slf4j
@RestController
@CrossOrigin//支持跨域
public class HotelController {
    //用来记录日志
  //  private static Logger log = LoggerFactory.getLogger(HotelController.class);
    @Autowired
    private HotelService hotelService;

    @Autowired
    private OrderService orderService;

    /*
    查询全部房间信息
     */
    @GetMapping("/Hotel/selectAll")
    public Result select(){
        log.info("查询全部房间信息：");
       List<Hotel> hotel =  hotelService.select();//注意要用集合来接收
   //     log.info(hotel.toString());
        return Result.success(hotel);
    }

    /*
    查询可预订的房间信息
     */
    @GetMapping("/Hotel/selectBook")
    public Result list(){
        log.info("查询可预订房间的信息：");
        List<Hotel> hotel =  hotelService.list();
        return Result.success(hotel);
    }

     /*
    预定酒店房间  根据传进来的id预订房间  路径参数  修改房间数量  没有返回值，只有查询才有返回值
     */
    @PutMapping("/Hotel/update/{id}")//注意这里的id被当做路径参数来传递了
    public void update(@PathVariable int id,String name, int number,int price){
        log.info("预定酒店房间：");
        orderService.insertHotel(name,number,price);
        hotelService.update(id,number);

    }


    /*
    添加酒店房间
     */
    @PostMapping("/Hotel/add")
    public void add(@RequestBody Hotel hotel){//接收json格式的数据并且封装到实体类中
        log.info("添加酒店房间：");
        hotelService.add(hotel);
    }

    /*
    根据id删除酒店房间
     */
    @DeleteMapping("/Hotel/delete/{id}")
    public void delete(@PathVariable int id){
        log.info("删除酒店房间");
        hotelService.delete( id);
    }
}
